package com.ruoyi.web.controller.controller;

import com.ruoyi.web.controller.entity.Curd;
import com.ruoyi.web.controller.service.curdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class curdController {
    @Autowired
    private curdService service;
    @GetMapping("/r")
    public String getAll(ModelMap map){
        List< Curd > all = service.getAll();
        map.put("all",all);
        return "hello";
    }

    @PostMapping("/cc")
    public String cc(){
        return "curdAdd";
    }

    @PostMapping("/c")
    public String addCurd(Curd curd){
        service.addCurd(curd);
        return "redirect:/r";
    }
    @RequestMapping("/d/{id}")
    public String delCurd(@PathVariable int id){
        service.delCurd(id);
        return "redirect:/r";
    }

    @GetMapping("/u/{id}")
    public String uu(ModelMap map,@PathVariable int id){
        System.out.println("我是修改跳转"+id);
        Curd curd = service.getById(id);
        System.out.println(curd);
        map.put("uu",curd);
        return "update";
    }

    @PostMapping("/uu")
    public String update(ModelMap map,Curd curd){
        System.out.println("这是修改controller");
        service.updateCurd(curd);
        List< Curd > all = service.getAll();
        map.put("all",all);
        return "hello";
    }

}
